# - try to find the cutil library provided with the cuda SDK
#  CUTIL_INCLUDE_DIR, where to find cutil.h, etc.
#  CUTIL_LIBRARIES, the libraries to link against
#  CUTIL_FOUND, If false, do not try to use GLUT.

# the path to the SDK (CUDA_SDK_ROOT_DIR) needs to be defined while looking for the cuda library like ~/NVIDIA_GPU_Computing_SDK/C/

IF (WIN32)
  FIND_PATH( CUTIL_INCLUDE_DIR NAMES cutil.h
    PATHS  
      ${CUDA_SDK_ROOT_DIR}/common/inc
)
  FIND_LIBRARY( CUTIL_LIBRARY NAMES cutil cutil32
    PATHS
     ${CUDA_SDK_ROOT_DIR}/common/lib/win32/
    )
ELSE (WIN32)
  
  IF (APPLE)
  ELSE (APPLE)
    
    FIND_PATH( CUTIL_INCLUDE_DIR cutil.h
	PATHS
      ${CUDA_SDK_ROOT_DIR}/common/inc
      /usr/local/include
      /usr/cuda/include
      )
  
    FIND_LIBRARY( CUTIL_LIBRARY libcutil_x86_64.a libcutil_x86_32.a
	PATHS
      /usr/openwin/lib
      /usr/cuda/lib
      /usr/lib
     ${CUDA_SDK_ROOT_DIR}/lib
      )
    
  ENDIF (APPLE)

ENDIF (WIN32)

SET( CUTIL_FOUND OFF )
IF(CUTIL_INCLUDE_DIR)
  IF(CUTIL_LIBRARY)
    SET( CUTIL_LIBRARIES
      ${CUTIL_LIBRARY}
      )
    SET( CUTIL_FOUND ON )
    
    SET (CUTIL_LIBRARY ${CUTIL_LIBRARIES})
    SET (CUTIL_INCLUDE_PATH ${CUTIL_INCLUDE_DIR})
    
  ENDIF(CUTIL_LIBRARY)
ENDIF(CUTIL_INCLUDE_DIR)

MARK_AS_ADVANCED(
  CUTIL_INCLUDE_DIR
  CUTIL_LIBRARY
  )
